package org.csmz.xg2333;

import java.util.HashMap;
import java.util.Set;
import java.util.Map;

public class Example14 {
    public static void main(String[] args){
        HashMap<String,Integer> map = new HashMap<>();
        map.put("钢笔",99);
        map.put("毛笔",199);
        map.put("铅笔",15);
        map.put("钢笔",199);
        Set<String> Keys = map.keySet();
        System.out.println("1.用第一种方法遍历map集合");
        for (String key:Keys){
            Integer value = map.get(key);
            System.out.println(key+"->"+value);
        }
        Set<Map.Entry<String,Integer>> entries = map.entrySet();
        System.out.println("2.用第二种方法遍历map集合");
        for (Map.Entry<String,Integer> entry:entries){
            String key = entry.getKey();
            Integer value = entry.getValue();
            System.out.println(key+"->"+value);
        }
    }
}
